

























local function template(name,config)

local assets=
{
Asset("ATLAS","images/inventoryimages/"..name..".xml"),
Asset("IMAGE","images/inventoryimages/"..name..".tex"),
Asset("ANIM","anim/"..name..".zip"),
}

local function onequip(inst,owner)
owner.AnimState:OverrideSymbol("swap_hat",name,"swap_hat")

owner.AnimState:Show("HAT")
if not config.keepHead then
owner.AnimState:Show("HAIR_HAT")
owner.AnimState:Hide("HAIR_NOHAT")
owner.AnimState:Hide("HAIR")
end

if owner:HasTag("player") and not config.keepHead then
owner.AnimState:Hide("HEAD")
if not config.hideHead then
owner.AnimState:Show("HEAD_HAT")
end
end

if inst.components.fueled~=nil then
inst.components.fueled:StartConsuming()
end

if config.onEquip~=nil then
config.onEquip(inst,owner)
end
end

local function onunequip(inst,owner)
owner.AnimState:ClearOverrideSymbol("swap_hat")

owner.AnimState:Hide("HAT")
if not config.keepHead then
owner.AnimState:Hide("HAIR_HAT")
owner.AnimState:Show("HAIR_NOHAT")
owner.AnimState:Show("HAIR")
end

if owner:HasTag("player") and not config.keepHead then
owner.AnimState:Show("HEAD")
if not config.hideHead then
owner.AnimState:Hide("HEAD_HAT")
end
end

if inst.components.fueled~=nil then
inst.components.fueled:StopConsuming()
end

if config.onUnequip~=nil then
config.onUnequip(inst,owner)
end
end

local function fn()
local inst=CreateEntity()

inst.entity:AddTransform()
inst.entity:AddAnimState()
inst.entity:AddNetwork()

MakeInventoryPhysics(inst)

inst.AnimState:SetBank(name)
inst.AnimState:SetBuild(name)
inst.AnimState:PlayAnimation("anim")

inst:AddTag("hat")
inst:AddTag("waterproofer")

inst.entity:SetPristine()

if not TheWorld.ismastersim then
return inst
end

inst:AddComponent("inventoryitem")
inst.components.inventoryitem.atlasname="images/inventoryimages/"..name..".xml"

inst:AddComponent("inspectable")

inst:AddComponent("tradable")

inst:AddComponent("equippable")
inst.components.equippable.equipslot=EQUIPSLOTS.HEAD
inst.components.equippable:SetOnEquip(onequip)
inst.components.equippable:SetOnUnequip(onunequip)
if config.walkspeedmult then
inst.components.equippable.walkspeedmult=config.walkspeedmult
end
if config.dapperness then
inst.components.equippable.dapperness=config.dapperness
end


if config.fueled then
inst:AddComponent("fueled")
inst.components.fueled.fueltype=FUELTYPE.USAGE
inst.components.fueled:InitializeFuelLevel(config.fueled.level)
inst.components.fueled:SetDepletedFn(inst.Remove)
end

MakeHauntableLaunch(inst)


if config.waterproofer then
inst:AddComponent("waterproofer")
inst.components.waterproofer:SetEffectiveness(TUNING.WATERPROOFNESS_SMALL)
end


if config.armor then
inst:AddComponent("armor")
inst.components.armor:InitCondition(config.armor.amount,config.armor.absorb_percent*(TUNING.ARMORWOOD_ABSORPTION/.8))

if config.armor.tag then
inst.components.armor:SetTags(config.armor.tag)
end
end


if config.postInst then
config.postInst(inst)
end

return inst
end

return Prefab(name,fn,assets,config.prefabs)
end

return template